package com.jeecms.edu.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;
import com.jeecms.common.web.ResponseUtils;
import com.jeecms.edu.entity.SchoolInformation;

/**
 * 热门标签 页面
 */
@SuppressWarnings("serial")
@WebServlet("/HotSearchServlet")
public class HotSearchServlet extends HttpServlet {
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		String search=request.getParameter("searchs");
		String sql=""; //条件语句
		switch (search) {
		case "示范园幼儿园":
			sql=" and schoollength='幼儿园' and schoollevel='示范园'";
			break;
		case "民办小学":
			sql=" and schoolnature='民办' and schoollength in('9年制学校','12年制学校','小学')";
			break;
		case "民办初中":
			sql=" and schoolnature='民办' and schoollength in('9年制学校','4年制初级中学','12年制学校','7年制完全中学')";
			break;
		case "重点高中":
			sql=" and otherschoolkey=1 and schoollength in('12年制学校','3年制高级中学','7年制完全中学')";
			break;
		case "9年制学校":
			sql=" and schoollength='9年制学校'";
			break;
		case "12年制学校":
			sql=" and schoollength='12年制学校'";
			break;
		}
		List searchlist=SchoolInformation.getPageSchool(sql);
		JSONObject jsonObject=new JSONObject();
		if (null!=searchlist && searchlist.size()!=0) {
			request.getSession().getServletContext().setAttribute("schoollist", searchlist);
			request.getSession().getServletContext().setAttribute("exadd", search);
			jsonObject.put("report", "0");
			String json = jsonObject.toJSONString();
			ResponseUtils.renderJson(response, json); 
		}else{
			jsonObject.put("report", "1");
			String json = jsonObject.toJSONString();
			ResponseUtils.renderJson(response, json);
		}
	}

}
